package com.yx.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yx.entity.Stock;
import com.yx.services.IStockService;
import com.yx.vo.StockParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Classname StockerController
 * @Date 2021/07/09 19:01
 * @Author by yx
 * @Description TODO:
 */
@RestController
@RequestMapping("/stock")
@Slf4j
public class StockController {

    @Autowired
    private IStockService stockService;

    @PostMapping("/addStock")
    public Boolean addStock(@RequestBody Stock stock){
        return stockService.save(stock);
    }

    @GetMapping("/getStockByGid/{id}")
    public Stock getStockByGid(@PathVariable("id") Integer id){
        //根据商品id查询stock
        QueryWrapper<Stock> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("gid", id);
        return stockService.getOne(queryWrapper);
    }

    /*
     * 库存扣减
     * */
    @RequestMapping("/lockGoodsStock")
    public Boolean lockGoodsStock(@RequestBody List<StockParam> stockParamList){
        return stockService.lockGoodsStock(stockParamList);
    }
}
